package app.lee.com.gesture;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import app.lee.com.view.GestureLockView;

public class ChangeActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btnConfirm,btnq;
    private SharedPreferences sp;
    private GestureLockView changeGv;
    private String result;
    public ChangeActivity() {
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change);
        changeGv = (GestureLockView) findViewById(R.id.changeGv);
        btnConfirm = (Button) findViewById(R.id.btnConfirm);
        btnq= (Button) findViewById(R.id.btnQ);
        btnConfirm.setOnClickListener(this);
        btnq.setOnClickListener(this);
        sp = this.getSharedPreferences("config", MODE_PRIVATE);
        changeGv.setIsSetting(true);
        changeGv.setOnGestureFinishListener(new GestureLockView.OnGestureFinishListener() {
            @Override
            public void OnGestureFinish(boolean result) {

            }
            @Override
            public void OnSettingFinish(String str) {
                result = str;

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnConfirm:
                SharedPreferences.Editor editor = sp.edit();
                editor.putString("pwd", result);
                editor.commit();
                Toast.makeText(ChangeActivity.this, "修改完成",
                        Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(ChangeActivity.this, MainActivity.class);
                startActivity(intent);
                break;
            case R.id.btnQ:
                finish();
            default:
                break;
        }

    }

}
